package com.jumper.study.front.dto.req;

import com.jumper.study.common.dto.PageSearchReq;

import cn.hutool.core.util.ArrayUtil;

public class LessonSearchReq extends PageSearchReq {
    private static final String[] sortFields = {"id", "price", "sort"};

    private static final String[] sortDirects = {"asc", "desc", "ASC", "DESC"};

    private final String defaultSortField = "sort";

    private final String defaultSortDirect = "desc";

    private Long categoryId;

    private String title;

    private String sort;

    private String sortDirect;

    public Long getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSort() {
        if (ArrayUtil.contains(sortFields, sort)) {
            return sort;
        }
        return defaultSortField;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getSortDirect() {
        if (ArrayUtil.contains(sortDirects, sortDirect)) {
            return sortDirect;
        }
        return defaultSortDirect;
    }

    public boolean isAsc() {
        return "asc".equals(getSortDirect());
    }

    public void setSortDirect(String sortDirect) {
        this.sortDirect = sortDirect;
    }
}
